/****** Object:  Stored Procedure [dbo].spNhaCungCapInsert Script Date: 6/11/2012 ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[spNhaCungCapInsert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
	DROP PROCEDURE [dbo].[spNhaCungCapInsert]
GO

/******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:					Description:
**		--------	--------				-----------------------------------
**		12/06/2012	SongTM					Innit created
*******************************************************************************/

CREATE PROCEDURE [dbo].[spNhaCungCapInsert]
(
	@MaNCC nvarchar(6) output,
	@TenNCC nvarchar(50),
	@DiaChi nvarchar(80),
	@SoDT nvarchar(15),
	@SoFax nvarchar(15),
	@MaSoThue nvarchar(15),
	@Email nvarchar(30),
	@Website nvarchar(35),
	@GhiChu nvarchar(100)
)
WITH ENCRYPTION

AS

SET NOCOUNT ON
if not exists (select * from [tbl_NhaCungCap])
	Set @MaNCC=1
else
	Set @MaNCC=(select RIGHT(MAX([MaNCC]),3) from [tbl_NhaCungCap])+1
Set @MaNCC='NCC'+REPLICATE('0',3-LEN(@MaNCC))+@MaNCC  
INSERT INTO [tbl_NhaCungCap]
(
	[MaNCC],
	[TenNCC],
	[DiaChi],
	[SoDT],
	[SoFax],
	[MaSoThue],
	[Email],
	[Website],
	[GhiChu]
)
VALUES
(
	@MaNCC,
	@TenNCC,
	@DiaChi,
	@SoDT,
	@SoFax,
	@MaSoThue,
	@Email,
	@Website,
	@GhiChu
)
GO

--GRANT EXECUTE ON [dbo].[spNhaCungCapInsert] TO [sa]
--GO
